# -*- coding: utf-8 -*-
from common import orm
from common.utils.types import Enum

PAY_TYPE = Enum({
    "APPLE": (1L, u"苹果支付"),
    "SELF_ALIPAY": (101L, "self alipay"),
    "SELF_BANK": (102L, "self bank"),
    "SELF_WECHAT": (103L, "self wechat"),
    "JUSTPAY_WX": (1000L, u"内部聚合支付微信"),
    "JUSTPAY_ALI": (1001L, u"内部聚合支付支付宝"),
    "JUSTPAY_ALI_QUOTA": (1011L, u"内部聚合支付支付宝定额"),
    "JUSTPAY_UNION": (1002L, u"内部聚合支付银联"),
    "JUSTPAY_QQ": (1012L, u"内部聚合支付qq"),
    "JUSTPAY_JD": (1013L, u"内部聚合支付jd"),
    "UNIONAGENCY": (1014L, u"内部银行卡代理下分V1"),
    "UNIONAGENCY_V2_ALI": (1015L, u"内部银行卡代理下分V2支付宝"),
    "UNIONAGENCY_V2_BANKCARD": (1016L, u"内部银行卡代理下分V2银行卡"),
    "UNIONAGENCY_V2_WX": (1017L, u"内部银行卡代理下分V2微信"),
    "JUSTPAY_TEST": (1111L, u"内部聚合支付测试通道"),
    "JUSTPAY_WX_QUOTA": (1018L, u"内部聚合微信定额"),
})

PAY_SERVICE_NAMES = {
    'wechat': '1000',
    'alipay': '1001',
    'quota_alipay': '1011',
    'unionpay': '1002',
    'qq': '1012',
    'jd': '1013',
    'test': '1111',
}

PAY_STATUS = Enum({
    "WAIT": (0L, "wait"),
    "SUBMIT": (1L, "submit to third"),
    "DONE": (2L, "finished"),
    "FAIL": (4L, "fail"),
    "CANCEL": (8L, "cancel")
})

# PAY_TYPE_DCT = {
#     1: u'苹果支付',
#     101: u'支付宝',
#     102: u'银行',
#     103: u'微信',
#     1000: u'微信',
#     1001: u'支付宝',
#     1002: u'银联快捷支付',
#     1011: u'测试通道',
#     1012: u'QQ钱包支付',
#     1013: u'京东支付',
#     1014: u'线下转账支付',
#     1015: u'支付宝转账（送2%)',
#     1016: u'银行卡转账（送2%)',
#     1017: u'微信转账（送2%)',
#     1111: u'TEST',
#     1200: u'定额支付'
# }

CREATED_BY_TYPE = Enum({
    "USER": (0, "user"),
    "THIRD": (1, "third"),
    "CONSOLE": (2, "console"),
})


class Pay(orm.Model):
    __tablename__ = "pay"
    id = orm.Column(orm.BigInteger, primary_key=True, autoincrement=False)
    user_id = orm.Column(orm.BigInteger)
    pay_type = orm.Column(orm.Integer)  # 支付类型
    status = orm.Column(orm.Integer)  # 交易是否完成，默认为0
    price = orm.Column(orm.FLOAT)  # 金额
    extend = orm.Column(orm.TEXT)  # json, 附加信息，具体购买内容
    third_id = orm.Column(orm.TEXT)  # 第四方支付交易号
    created_by = orm.Column(orm.Integer, default=0)  # 谁创建的订单，0：用户 ，1：第三方，2：控制台
    target_id = orm.Column(orm.TEXT)  # 原始的微信/支付宝/银行交易号
    created_at = orm.Column(orm.DATETIME)
    updated_at = orm.Column(orm.DATETIME)
